/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.football.lottery.ui;

import java.awt.Color;
import javax.swing.JCheckBox;
import javax.swing.JPanel;

/**
 *
 * @author JingWen.Wen
 */
public class CheckboxPanel extends JPanel
{
  private JCheckBox box3;
  private JCheckBox box1;
  private JCheckBox box0;
  private JCheckBox[] boxes;

  public CheckboxPanel(String value)
  {
    box3 = new JCheckBox("3", false);
    box1 = new JCheckBox("1", false);
    box0 = new JCheckBox("0", false);
    boxes = new JCheckBox[3];
    boxes[0] = box3;
    boxes[1] = box1;
    boxes[2] = box0;
    add(box3);
    add(box1);
    add(box0);
    
    init(value);
  }

  public CheckboxPanel()
  {
  }

  public JCheckBox[] getBoxes()
  {
    return boxes;
  }

  private void init(String value)
  {
    if (value != null && value.length() > 0)
    {
      box3.setSelected(value.contains("3"));
      box1.setSelected(value.contains("1"));
      box0.setSelected(value.contains("0"));
    }
  }

  public void setValue(String value)
  {
    init(value);
  }

  public String getValue()
  {
    String value = "";
    value += box3.isSelected() ? "3" : "";
    value += box1.isSelected() ? "1" : "";
    value += box0.isSelected() ? "0" : "";

    return value;
  }
  
  public void setCheckBoxBackground(Color color)
  {
    if (boxes != null)
    {
      for (JCheckBox box : boxes)
      {
        box.setBackground(color);
      }
    }
  }
}
